'use strict'

let util = require('util');
let Fiber = require('fibers');

let csv = require('../modules/lib/csv');
let CsvParser = csv.CsvParser;
let redis = require('../modules/lib/redis');
let outputLogger = require('../modules/lib/loggers').output;
let DATA_SYNC_DB = 1;
let DATA_SYNC_KEY = 'attendance_data_sync';
let TEST_SYNC_KEY = 'test_data_sync';
let TIMEOUT = 2000;

let models = require('../modules/models');

let User = models.User;
let Role = models.Role;
let School = models.School;
let NatureClass = models.NatureClass;
let Student = models.Student;
let Teacher = models.Teacher;
let Grade = models.Grade;
let Attendance = models.Attendance;
let AttendanceValue = models.AttendanceValue;
let AttendanceStatus = models.AttendanceStatus;

let UserDao = models.UserDao;
let RoleDao = models.RoleDao;
let SchoolDao = models.SchoolDao;
let NatureClassDao = models.NatureClassDao;
let StudentDao = models.StudentDao;
let TeacherDao = models.TeacherDao;
let GradeDao = models.GradeDao;
let AttendanceDao = models.AttendanceDao;
let AttendanceValueDao = models.AttendanceValueDao;

Fiber(() => {
    let students = StudentDao.find({});

    students.forEach(student => {
        console.log(student.name);
        // 创建考勤数据
        let today = new Date();
        today.setHours(0);
        today.setMinutes(0);
        today.setSeconds(0);
        for ( let dayIndex = 0; dayIndex < 7; dayIndex ++ ) {
            let attendance = new Attendance({
                student: student,
                date: today,
                values: [
                    new AttendanceValue({
                        enterStatus: AttendanceStatus.Created,
                        exitStatus: AttendanceStatus.Created
                    }),
                    new AttendanceValue({
                        enterStatus: AttendanceStatus.Created,
                        exitStatus: AttendanceStatus.Created
                    }),
                    new AttendanceValue({
                        enterStatus: AttendanceStatus.Created,
                        exitStatus: AttendanceStatus.Created
                    })
                ]
            });

            attendance.values.forEach(value => AttendanceValueDao.create(value));
            AttendanceDao.create(attendance);

            today = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
        }
    });

    process.exit();
}).run();

